/* This file is part of the
   ___                   _              __    __ _                  _ 
  /___\__ _ _ __ ___    /_\  _ __  _ __/ / /\ \ (_)______ _ _ __ __| |
 //  // _` | '__/ _ \  //_\\| '_ \| '_ \ \/  \/ / |_  / _` | '__/ _` |
/ \_// (_| | | |  __/ /  _  \ |_) | |_) \  /\  /| |/ / (_| | | | (_| |
\___/ \__, |_|  \___| \_/ \_/ .__/| .__/ \/  \/ |_/___\__,_|_|  \__,_|
      |___/                 |_|   |_|                                 
	  Ogre 1.7.x Application Wizard for VC10 (July 2011)
-----------------------------------------------------------------------------
 Portions copyright (c) Microsoft Corporation.  All rights reserved.  */
var bCopyOnly = false;

function OnFinish(selProj, selObj)
{
	try
	{
		var strProjectPath = wizard.FindSymbol("PROJECT_PATH");
		var strProjectName = wizard.FindSymbol("PROJECT_NAME");
		var strSafeProjectName = wizard.FindSymbol("SAFE_PROJECT_IDENTIFIER_NAME");

		var bEmptyProject = wizard.FindSymbol("EMPTY_PROJECT");

		selProj = CreateProject(strProjectName, strProjectPath);
   
		AddCommonConfig(selProj, strProjectName);
		AddSpecificConfig(selProj, strProjectName, bEmptyProject);
		
        SetupFilters(selProj);

		if (!bEmptyProject)
		{
			var InfFile = CreateInfFile();
            AddFilesToProjectWithInfFile(selProj, strSafeProjectName);
			SetCommonPchSettings(selProj);
			InfFile.Delete();
			var projName = strProjectPath + "\\" + strProjectName + ".vcproj";
			selProj.Object.Save();
		}
	}
	catch(e)
	{
		if (e.description.length != 0)
			SetErrorInfo(e);
		return e.number
	}
}

function GetTargetName(strName, strProjectName, strResourcePath)
{
	var strTarget = strName;

		switch (strName)
		{
			case "docs/readme.txt":
				strTarget = "docs/ReadMe.txt";
				break;
			case "res/resource.h":
				strTarget = "res/Resource.h";
				break;
			case "res/root.ico":
				strTarget = "res" + "\\" + strProjectName + ".ico";
				break;
			case "res/root.rc":
				strTarget = "res" + "\\" + strProjectName + ".rc";
				break;
			case "include/root.h":
				strTarget = "include" + "\\" + strProjectName + ".h";
				break;
			case "src/root.cpp":
				strTarget = "src" + "\\" + strProjectName + ".cpp";
				break;
			case "include/root_mini.h":
				strTarget = "include" + "\\" + strProjectName + ".h";
				break;
			case "src/root_mini.cpp":
				strTarget = "src" + "\\" + strProjectName + ".cpp";
				break;
			case "include/root_one.h":
				strTarget = "include" + "\\" + strProjectName + ".h";
				break;
			case "src/root_one.cpp":
				strTarget = "src" + "\\" + strProjectName + ".cpp";
				break;
			default:
				break;
		}
	return strTarget; 
}


function AddSpecificConfig(proj, strProjectName, bEmptyProject)
{
	var bPostbuildCopy = wizard.FindSymbol('POSTBUILD_COPY');

	strOgreMainDir = '$(OGRE_HOME)';
	
//DEBUG//////////////////////////////////////////////////////
//set configurations for debug|win32

	var config = proj.Object.Configurations("Debug|Win32");
	config.IntermediateDirectory = 'obj\\$(Configuration)\\';
	config.OutputDirectory = 'bin\\$(Configuration)\\';
	config.CharacterSet = charSetMBCS;
	
	var debugSettings = config.DebugSettings;
	if(bPostbuildCopy)
	{
		debugSettings.WorkingDirectory = strOgreMainDir + "\\Bin\\$(Configuration)";
		debugSettings.Command = strOgreMainDir + "\\Bin\\$(Configuration)\\$(ProjectName).exe";
	}
	else
	{
		debugSettings.WorkingDirectory = "$(ProjectDir)\\Bin\\$(Configuration)";
		debugSettings.Command = "$(ProjectDir)\\Bin\\$(Configuration)\\$(ProjectName).exe";
	}


	var CLTool = config.Tools("VCCLCompilerTool");
	CLTool.UsePrecompiledHeader = pchNone;

	CLTool.RuntimeLibrary = rtMultiThreadedDebugDLL;
	CLTool.MinimalRebuild = true;
	CLTool.DebugInformationFormat = debugEditAndContinue;
	CLTool.BasicRuntimeChecks = runtimeBasicCheckAll;
	CLTool.Optimization = optimizeDisabled;
	CLTool.ExceptionHandling = cppExceptionHandlingYes;
	CLTool.RuntimeTypeInfo = true;
	CLTool.floatingPointModel = FloatingPointFast;

	CLTool.EnableFunctionLevelLinking = true;
	CLTool.MinimalRebuild = true;
	CLTool.WarningLevel = WarningLevel_3;
	CLTool.PreprocessorDefinitions = "WIN32;_DEBUG;_WINDOWS";

	strAdditionalIncludeDirectories = "include;" + strOgreMainDir + "\\include;" + strOgreMainDir + "\\include\\OIS;" + strOgreMainDir + "\\include\\OGRE;" + strOgreMainDir + "\\Samples\\Common\\include;" + strOgreMainDir + "\\boost_1_44";

	CLTool.AdditionalIncludeDirectories = strAdditionalIncludeDirectories;

	var LinkTool = config.Tools("VCLinkerTool");

	LinkTool.ProgramDatabaseFile = "$(TargetDir)\\$(TargetName)" + ".pdb";
	LinkTool.GenerateDebugInformation = true;
	LinkTool.ProgramDatabaseFile = "$(OutDir)/" + strProjectName + ".pdb";
	LinkTool.LinkIncremental = linkIncrementalYes;
	LinkTool.SubSystem = subSystemWindows;
	LinkTool.OutputFile = "$(OutDir)\\$(ProjectName)" + ".exe";
	LinkTool.TargetMachine = machineTypeOption.machineX86;

	strAdditionalLibraryDirectories = strOgreMainDir + "\\lib\\debug;" + strOgreMainDir + "\\boost_1_44\\lib";
	strAdditionalDependencies = "OgreMain_d.lib OIS_d.lib";
		
	LinkTool.AdditionalLibraryDirectories = strAdditionalLibraryDirectories;
	LinkTool.AdditionalDependencies = strAdditionalDependencies;

	if(bPostbuildCopy)
	{
		var PostBuildTool = config.Tools("VCPostBuildEventTool");
		PostBuildTool.Description = "Copying exe to samples bin directory ...";

		PostBuildTool.CommandLine = 'copy "$(OutDir)\\$(TargetFileName)" "' + strOgreMainDir + '\\Bin\\$(Configuration)"';
	}
    
    
//RELEASE//////////////////////////////////////////////////////
//set configurations for release|win32

	config = proj.Object.Configurations.Item("Release|Win32");
	config.IntermediateDirectory = 'obj\\$(Configuration)\\';
	config.OutputDirectory = 'bin\\$(Configuration)\\';
	config.CharacterSet = charSetMBCS;
	
	debugSettings = config.DebugSettings; // refresh for release conf
	
	if(bPostbuildCopy)
	{
		debugSettings.WorkingDirectory = strOgreMainDir + "\\Bin\\$(Configuration)";
		debugSettings.Command = strOgreMainDir + "\\Bin\\$(Configuration)\\$(ProjectName).exe";
	}
	else
	{
		debugSettings.WorkingDirectory = "$(ProjectDir)\\Bin\\$(Configuration)";
		debugSettings.Command = "$(ProjectDir)\\Bin\\$(Configuration)\\$(ProjectName).exe";
	}

	var CLTool = config.Tools("VCCLCompilerTool");
	CLTool.UsePrecompiledHeader = pchNone;

	CLTool.RuntimeLibrary = rtMultiThreadedDLL;
	CLTool.ExceptionHandling = cppExceptionHandlingYes;
	CLTool.RuntimeTypeInfo = true;
	CLTool.DebugInformationFormat = debugEnabled;
	CLTool.WarningLevel = WarningLevel_3;
	CLTool.PreprocessorDefinitions = "WIN32;NDEBUG;_WINDOWS";
	CLTool.EnableFunctionLevelLinking = true;
	CLTool.MinimalRebuild = true;
	CLTool.FavorSizeOrSpeed = favorSizeOrSpeedOption.favorSpeed;
	CLTool.InlineFunctionExpansion = inlineExpansionOption.expandOnlyInline;
	CLTool.OmitFramePointers = true;
	CLTool.StringPooling = true;
	CLTool.InlineFunctionExpansion = expandOnlyInline;
	CLTool.BufferSecurityCheck = false;
	CLTool.floatingPointModel = FloatingPointFast;
	CLTool.EnableIntrinsicFunctions = true;
	
	strAdditionalIncludeDirectories = "include;" + strOgreMainDir + "\\include;" + strOgreMainDir + "\\include\\OIS;" + strOgreMainDir + "\\include\\OGRE;" + strOgreMainDir + "\\Samples\\Common\\include;" + strOgreMainDir + "\\boost_1_44";
		
	CLTool.AdditionalIncludeDirectories = strAdditionalIncludeDirectories;

	var LinkTool = config.Tools("VCLinkerTool");
	LinkTool.GenerateDebugInformation = false;
	LinkTool.LinkIncremental = linkIncrementalNo;

	LinkTool.SubSystem = subSystemWindows;

	LinkTool.OutputFile = "$(OutDir)\\$(ProjectName)" + ".exe";

	strAdditionalLibraryDirectories = strOgreMainDir + "\\lib\\release;" + strOgreMainDir + "\\boost_1_44\\lib";
		
	strAdditionalDependencies = "OgreMain.lib OIS.lib";
		
	LinkTool.AdditionalLibraryDirectories = strAdditionalLibraryDirectories;
	LinkTool.AdditionalDependencies = strAdditionalDependencies;
	
	if(bPostbuildCopy)
	{
		var PostBuildTool = config.Tools("VCPostBuildEventTool");
		PostBuildTool.Description = "Copying exe to samples bin directory ...";

		PostBuildTool.CommandLine = 'copy "$(OutDir)\\$(TargetFileName)" "' + strOgreMainDir + '\\Bin\\$(Configuration)"';
	}

}

function SetFileProperties(projfile, strName)
{
	return false;
}

function DoOpenFile(strTarget)
{
	return false;
}
